package com.packet.controller;

import com.packet.pojo.Staff;
import com.packet.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * @className:LoginController
 * @Author:wallet_packet Date:2023-11-12 10:38
 * @Describe:
 */
@Controller
public class LoginController {

    @Autowired
    UserLoginService userLoginService;

    @RequestMapping("/finance/user/login")
    public String login(@RequestParam("sId") String sId,
                        @RequestParam("sPassword") String sPassword,
                        Model model, HttpSession session) {
        System.out.println("你好");
        Staff staff = userLoginService.selectById(Integer.parseInt(sId));
        if(staff.getSPassword().equals(sPassword)){
            session.setAttribute("loginUser",staff.getSName());
            session.setAttribute("sid",staff.getSId());
            return "dashboard";
        } else {
            model.addAttribute("msg","密码错误");
            return "index";
        }
    }
    @RequestMapping("/user/logOut")
    public String logOut(HttpSession session){
        session.invalidate();
        return "index";
    }
}
